<?php
/**
 * 
 * @author tangbl
 *
 */
class PublicAction extends CommonAction{
	
	
	/**
	 * 应用首页
	 */
	public function index(){
		
		redirect(__APP__);
	}
	
	public function test_onefile(){
		$this->assign('UPLOAD_PATH',UPLOAD_PATH);
		
		$this->display();
	}
	
	/**
	 * 添加桌面快捷
	 */
	public function addApp(){
		
		$roleid = session(C('USER_AUTH_ROLE'));
		$userid = session(C('USER_AUTH_KEY'));
		
		if(IS_AJAX){
			
			$_POST['userid'] = $userid;
			$_POST['role']   = $roleid;
			$json = sendRest("BDC/Menu/quickUserEdit", $_POST, "POST");
			if($json['status'] == 1){
				import('@.ORG.RBAC');
				RBAC::getMenuList($roleid, $userid);
			}
			$this->ajaxReturn($json);
		}else{
			
			$map    = array("role"=>$roleid, "userid"=>$userid);
			$json   = sendRest("BDC/Menu/quickByUser",$map,"get");
			//echo createRestUrl("BDC/Menu/quickByUser",$map,"get");
			$this->assign("menu",$json["data"]);
			
			$this->display();
		}
	}
	
	/**
	 * 更换桌面背景
	 */
	public function desktop(){
	
		$userid = session(C('USER_AUTH_KEY'));
	
		if(IS_AJAX){
			
			$desk = $this->_param('desktop',"trim","");
			$map  = array("userid"=>$userid,"desktop"=>$desk);
			$json = sendRest("BDC/Admin/desktop",$map,"get");
			
			session(C('USER_DESKTOP'),$desk);
			
			$this->ajaxReturn($json);
		}else{			
			$this->display();
		}
	}
	
	/**
	 * 用户登陆
	 */
	public function login(){
		
		if(IS_POST){
			
			$verify = $this->_param('yzm',"trim","");
			if(session('verify') != md5(strtoupper($verify)) ){
				$this->error("验证码输入错误！");
			}
			
			$json = sendRest("BDC/Company/login", $_POST);
			if($json['status'] == 1){
				
				$user  = $json["data"];
				$model = D("Company");
				$model->setLoginSession($user);
		
				import('@.ORG.RBAC');
				RBAC::getAccessAction();
				RBAC::getAccessMenu();
				redirect(U("Index/index"));
			}else{
				$this->error($json['info']);
			}
		}else{
			
			$this->display();
		}
	}
	
	/**
	 * 无权限页面
	 */
	public function access(){
		
		$this->display();
	}
	
	/**
	 * 注销登陆
	 */
	public function logout() {
	
		$model = D("Company");
		$model->clearLoginSession();
		$this->success(L('pbc_login_logoutsucc'),U("Public/login"));
	}
	
	/**
	 * 显示验证码
	 */
	public function verify() {
		 
		$type	=	isset($_GET['type'])?$_GET['type']:'gif';
		import("ORG.Util.Image");
		Image::buildImageVerify(4,1,$type);
	}
}
